<?php
/**
 * 名称：AdminAction
 * 描述：后台界面设置管理
 * 作者：lan 时间：2013-05-02
 * 版本号：V1.0.0
 * ========================历史版本=================================
 * 序号	 版本号 	日期			姓名	 	描述
 * 1 	V1.0.0 	2013-05-02 	lan  	后台界面设置管理
 * ========================历史版本=================================
 * 说明：请在有更改程序的时候修改以上注释
 */
class UiAction extends CommonAction {

	/**
	 * 风格管理
	 * Create Data <2013-05-02>
	 */
	public function style() {
		import ( "ORG.Io.Dir" );
		$dirs = new Dir ('./apps/home/Tpl' );
		foreach ($dirs as $key => $value) {
		 	$ds[] = $value;
		}
		$changeStyle = model('Data')->lget('style');
		$this->assign($changeStyle);
		$this->assign('ds',$ds);
		$this->display();
	}
	
	/**
	 * 风格管理设置
	 * Create Data <2013-05-02>
	 */
	public function doStyle() {
		if (empty ($_POST)) {
			$this->error(L('parameterError')); //参数错误
		}
		$LOG['uid'] = $this->mid;
		$LOG['type'] = '3';
		$data[] = L("ui") . "-" . L("styleManage");
		$data[] = model('Data')->lget('style');
		if ($_POST['__hash__'])
			unset ($_POST['__hash__']);
		$data[] = $_POST;
		$LOG['data'] = serialize($data);
		$LOG['ctime'] = time();
		M('AdminLog')->add($LOG);
		$result = model('Data')->lput('style', $_POST);
		if ($result) {
			$fp = fopen ('./config/style.php', 'wb' );
			$chanage = $_POST['changestyle'];
			$str = <<<EOT
<?php			
	return array(
		'DEFAULT_THEME'=>'$chanage'
	);
?>
EOT;
			chmod ('./config/style.php', 0777 );
			$result_1 = fwrite ( $fp, trim ( $str ) );
			@fclose ( $fp );
			A('Index')->cleanRuntime2();
			$this->success(L('saveSuccess')); //保存成功
		} else {
			$this->error(L('saveFails')); //保存失败
		} 
	}

	/**
	 * 表情管理 
	 * Create Data <2013-05-02>
	 */
	public function expression() {
		$expression = model('Data')->lget('expression');
		import("ORG.Io.Dir");
		$expression_list = new Dir('./Public/expression/');
		foreach ($expression_list as $k => $v) {
			list($filenum) = common('File')->readGiveDir($v["pathname"], ".gif");
			$expressionPath[$k]["filename"] = $v["filename"];
			$expressionPath[$k]["pathname"] = $v["pathname"];
			$expressionPath[$k]["filenum"] = $filenum;
		}
		$this->assign('expression_list', $expressionPath);
		$this->assign($expression);

		$this->display();
	}

	/**
	 * 设置表情
	 * Create Data <2013-05-02>
	 */
	public function doSetExpression() {
		if (empty ($_POST)) {
			$this->error(L('parameterError')); //参数错误
		}
		$LOG['uid'] = $this->mid;
		$LOG['type'] = '3';
		$data[] = L("ui") . "-" . L("expressionSettings");
		$data[] = model('Data')->lget('expression');
		if ($_POST['__hash__'])
			unset ($_POST['__hash__']);
		$data[] = $_POST;
		$LOG['data'] = serialize($data);
		$LOG['ctime'] = time();
		M('AdminLog')->add($LOG);
		$result = model('Data')->lput('expression', $_POST);
		if ($result) {
			$this->success(L('saveSuccess')); //保存成功
		} else {
			$this->error(L('saveFails')); //保存失败
		}
	}

	/**
	 * 编辑器设置
	 * Create Data <2013-05-02>
	 */
	public function editor() {
		$editors = model('Data')->lget('editor');
		$this->assign($editors);
		$this->display();
	}

	/**
	 * 设置编辑器
	 * Create Data <2013-05-02>
	 */
	public function doSetEditor() {
		if (empty ($_POST)) {
			$this->error(L('parameterError')); //参数错误
		}
		$LOG['uid'] = $this->mid;
		$LOG['type'] = '3';
		$data[] = L("ui") . "-" . L("editorSettings");
		$data[] = model('Data')->lget('editor');
		if ($_POST['__hash__'])
			unset ($_POST['__hash__']);
		$data[] = $_POST;
		$LOG['data'] = serialize($data);
		$LOG['ctime'] = time();
		M('AdminLog')->add($LOG);
		$result = model('Data')->lput('editor', $_POST);
		if ($result) {
			$this->success(L('saveSuccess')); //保存成功
		} else {
			$this->error(L('saveFails')); //保存失败
		}
	}
}
?>